package com.saozhu.command;

import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;
import java.util.HashMap;
import java.util.Map;

import com.saozhu.pojo.Customer;
import com.saozhu.pojo.Player;



public class CustomerCommandFactory extends CommandFactory {

	private Player customer;
	public static Map<CommandCode,Class<? extends Command>> 
	              commandMap=new HashMap<>();
	public CustomerCommandFactory(Player c) {
		customer = c;
	}
	static {
//		commandMap.put(CommandCode.NEW,CustomerNewOrderCommand.class);
//		commandMap.put(CommandCode.PAY,CustomerPayOrderCommand.class);
//		commandMap.put(CommandCode.SHOW,CustomerShowCommand.class);
//		commandMap.put(CommandCode.HELP,CustomerHelpCommand.class);
//		commandMap.put(CommandCode.EXIT,CustomerExitCommand.class);
	}

	@Override
	public Command buildCommand(CommandCode cmd) {
		Class<? extends Command> clzz = commandMap.get(cmd);

		try {
			Constructor<? extends Command> c = clzz.getConstructor(Customer.class);
			Command command = c.newInstance(customer);
			return command;
		} catch (NoSuchMethodException e) {
			e.printStackTrace();
		} catch (SecurityException e) {
			e.printStackTrace();
		} catch (InstantiationException e) {
			e.printStackTrace();
		} catch (IllegalAccessException e) {
			e.printStackTrace();
		} catch (IllegalArgumentException e) {
			e.printStackTrace();
		} catch (InvocationTargetException e) {
			e.printStackTrace();
		} return null;
	}

}
